package day05;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * <>
 * <详细描述>
 * vector 增加 synchronized修饰,线程安全，效率比arrayList慢
 *
 * @Author WANG.SONG.
 * @Date 2019/2/27 0027 22:24
 * @see java.util.ArrayList
 * @see Vector
 */
public class ArrayAndVector {
    private static final int COUNT = 1000000;
    /**
     *<ArrayList插入数据100W>
     *@param
     *
     *@return
     *@Author WANG.SONG.
     */
    public static void ArrayListCompare(){
        List<Integer> integerList =new ArrayList<>();

        long start = System.currentTimeMillis();
        for (int i =0 ; i <= COUNT ; i++){
            integerList.add(i);
        }
        System.out.println(System.currentTimeMillis()-start);


    }
    /**
     *<vector插入数据100W>
     *@param
     *
     *@return
     *@Author WANG.SONG.
     */
    public static void VectorCompare(){
        List<Integer> integerList1 = new Vector<>();
        long start1 = System.currentTimeMillis();
        for (int i =0 ; i <= COUNT ; i++){
            integerList1.add(i);
        }
        System.out.println(System.currentTimeMillis()-start1);
    }

    public static void main(String[] args) {
        /**线程安全的执行效率低**/
        ArrayAndVector.ArrayListCompare();
        ArrayAndVector.VectorCompare();
    }
}
